/*
 * @Author: PU-TONG 1424838093@qq.com
 * @Date: 2023-06-28 07:13:44
 * @LastEditors: PU-TONG 1424838093@qq.com
 * @LastEditTime: 2023-06-29 01:53:28
 * @FilePath: /openharmony/device/board/isoftstone/qihang/app/My_pro/src/app_log.c
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "app_log.h"
#include <stdio.h>
#include <string.h>
#include "stdarg.h"
#include "mutex.h"

/**
 * @brief my_log_printf
 * @note  自定义的日志输出函数
 * @param tag
 * @param level
 * @param format
 * @param ...
 */
void my_log_printf(const char *tag, my_log_level_t level, const char *format, ...)
{
    // 获取互斥锁
    osMutexAcquire(log_mutexId, osWaitForever);

    // 输出日志级别和标签
    printf("[%s]", tag);
    switch (level)
    {
    case MY_LOG_ERROR:
        printf("[E]");
        break;
    case MY_LOG_WARN:
        printf("[W]");
        break;
    case MY_LOG_INFO:
        printf("[I]");
        break;
    case MY_LOG_DEBUG:
        printf("[D]");
        break;
    case MY_LOG_VERBOSE:
        printf("[V]");
        break;
    default:
        break;
    }

    // 输出格式化字符串
    va_list args;
    va_start(args, format);
    vprintf(format, args);
    va_end(args);

    // 释放互斥锁
    osMutexRelease(log_mutexId);
}
